package com.gameserver.controllers.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class AuthenticationInterceptor implements HandlerInterceptor {

	
	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object arg2) throws Exception {
		/*if(request.getHeader("Authorization") == null){
            String s = "Basic realm=\"Login Test Servlet Users\"";
            response.setHeader("WWW-Authenticate", s);
            response.setStatus(401);
            return false;
		}
		String auth_code = request.getHeader("Authorization");
		BASE64Decoder decoder = new BASE64Decoder();
        String userPass =
           new String(decoder.decodeBuffer(auth_code));
        
        String cred [] = userPass.split(":");
        if(cred[0].equals("geo") && cred[1].equals("man")){
        	return true;
        }else{
            String s = "Basic realm=\"Login Test Servlet Users\"";
            response.setHeader("WWW-Authenticate", s);
            response.setStatus(401);
            return false;
        }*/		
		return true;
	}
}
